package com.atguigu.yygh.common.exception;

import com.atguigu.yygh.common.result.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * SYT_Demo02
 * 2022/11/1 08 37
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    @ResponseBody
    public ResultCode.R error(Exception exception){
        exception.printStackTrace ();
        log.error (exception.getMessage ());
        return ResultCode.R.error ().message ("出现了异常！！！");
    }

    @ExceptionHandler(YyghException.class)
    public ResultCode.R error(YyghException yyghException){
        log.error (yyghException.getMgs ());
        return ResultCode.R.error ().message (yyghException.getMgs ());
    }
}
